package com.ssm.sfzy.controller;

import com.ssm.sfzy.constant.CommonConstant;
import com.ssm.sfzy.entity.TeacherLevel;
import com.ssm.sfzy.service.TeacherLevelService;
import com.ssm.sfzy.utils.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

/**
 * @ClassName TeacherLevelController
 * @Author xiaoliu
 * @Date 2024年03月30日 14:32
 */
@RestController
@CrossOrigin
@RequestMapping("/teacherLevel")
public class TeacherLevelController {
    @Autowired
    private TeacherLevelService teacherLevelService;

    @GetMapping("/find")
    public Object find(
            @RequestParam(defaultValue = CommonConstant.PAGE_NUM_DEFAULT) Integer pageNum,
            @RequestParam(defaultValue = CommonConstant.PAGE_SIZE_DEFAULT) Integer pageSize,
            TeacherLevel teacherLevel
    ){
        Map<String, Object> map = teacherLevelService.findPage(pageNum, pageSize, teacherLevel);
        return  Result.success(map);
    }

    @GetMapping("/findById/{id}")
    public Object findById(@PathVariable Integer id){
        TeacherLevel teacherLevel = teacherLevelService.findById(id);
        return Result.success(teacherLevel);
    }


    @PostMapping("/add")
    public Object add(@RequestBody TeacherLevel teacherLevel){
        teacherLevelService.add(teacherLevel);
        return Result.success();
    }

    @DeleteMapping("/remove/{id}")
    public Object remove(@PathVariable Integer id){
        teacherLevelService.remove(id);
        return Result.success();
    }

    @DeleteMapping("/removeBatch/{ids}")
    public Object removeBatch(Integer[] ids){
        teacherLevelService.removeBatch(ids);
        return Result.success();
    }

}
